from keras.layers import Dense, Dropout
import numpy as np
import pandas as pd
from keras import Sequential
from keras.utils import np_utils
import matplotlib.pyplot as plt

data = pd.read_csv("dataset/iris_training.csv", header=0)
data.columns = ['l1', 'l2', 'l3', 'l4', 'lei']

print(data)
data = np.array(data)
x_train = data[:110, :-1]
y_train = data[:110, -1]
x_test = data[110:, :-1]
y_test = data[110:, -1]

mean = x_train.mean(axis=0)
std = x_train.std(axis=0)
x_train = (x_train - mean) / std

mean = x_test.mean(axis=0)
std = x_test.std(axis=0)
x_test = (x_test - mean) / std

y_train = np_utils.to_categorical(y_train, num_classes=3)
y_test = np_utils.to_categorical(y_test, num_classes=3)

model = Sequential()
model.add(Dense(512, input_shape=(x_train.shape[1],), activation="relu"))
model.add(Dropout(0.2))
model.add(Dense(64, activation='relu'))
model.add(Dropout(0.2))
model.add(Dense(3, activation="softmax"))

model.compile(loss="categorical_crossentropy", optimizer='rmsprop', metrics=['accuracy'])

bath = 256
epoch = 600
split1 = 0.005
history = model.fit(x_train, y_train, batch_size=bath, epochs=epoch, validation_split=split1)

score = model.evaluate(x_test, y_test)
print(score[1])

plt.plot(history.history['loss'])
plt.plot(history.history['accuracy'])
plt.plot(history.history['val_loss'])
plt.plot(history.history['val_accuracy'])
plt.legend(['loss', 'accuracy', 'val_loss', 'val_accuracy'])
plt.savefig('result.png', dpi=300)
plt.show();



